package cn.lxh.remote.fallback;

import cn.lxh.remote.api.DriverFeignApi;
import cn.lxh.remote.pojo.result.DriverSummaryResult;
import cn.lxh.result.JSONResult;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author lxh Create Time: 2023/12/23 17:05
 * DriverFeignApiFallbackFactory熔断降级处理方案类
 */
@Component
public class DriverFeignApiFallbackFactory implements FallbackFactory<DriverFeignApi> {
    @Override
    public DriverFeignApi create(Throwable cause) {
        return new DriverFeignApi() {
            @Override
            public JSONResult<DriverSummaryResult> getDriverSummary(Long driverId) {
                cause.printStackTrace();
                return JSONResult.error("获取司机今日取消订单和今日投诉订单失败");
            }

            @Override
            public JSONResult addTodayComplaintOrder(Long driverId) {
                cause.printStackTrace();
                return JSONResult.error("添加司机今日投诉订单失败");
            }

            @Override
            public JSONResult subTodayComplaintOrder(Long driverId) {
                cause.printStackTrace();
                return JSONResult.error("减去司机今日投诉订单失败");
            }
        };
    }
}
